<?php
  if (!isset($_GET['op'])) {
    echo '参数错误，未授权的操作';
    return;
  }

require_once 'data/data.php';

$op = $_GET['op'];

$title = '添加学生信息';
$action = 'action/message.php';

$Number = '';
$Name = '';
$IDcard = '';
$Gender = 1;
$Birth = '';
$GradeS = [
  ['value' => 1,'text' => '大一'],
  ['value' => 2,'text' => '大二'],
  ['value' => 3,'text' => '大三'],
  ['value' => 4,'text' => '大四']
];
$Grade = 1;
$University = '';
$School = '';
$Major = '';
$GPA = '';
$description = '';

if ($op == 2) {
  $title = '修改学生信息';
  $action = 'action/message_edit.php';
  $id =  $_GET['id'];
  $sql ='select Number,Name,IDcard,Gender,Birth,Grade,University,School,Major,GPA,Introduction from students where ID=?';
  $student = query($sql,[$id])[0];

  $Number = $student['Number'];
  $Name = $student['Name'];
  $IDcard = $student['IDcard'];
  $Gender = $student['Gender'];
  $Birth = $student['Birth'];
  $Grade = $student['Grade'];
  $University = $student['University'];
  $School = $student['School'];
  $Major = $student['Major'];
  $GPA = $student['GPA'];
  $description = $student['Introduction'];
}
?>
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>注册页面</title>
</head>
<body>
  <form method="post" action="<?php echo $action ?>" target="_blank">
    <table width="500" border="1" align="center" cellspacing="0" cellpadding="2">
      <tr>
      <th align="center" colspan="2"><h1><?php echo $title ?></h1></th>
      </tr>
      <tr>
        <td align="right"><label for="Number">学&nbsp;&nbsp;&nbsp;号：</label></td>
        <td><input type="number" id="Number" name="Number" placeholder="Number" value="<?=$Number?>"></td>
      </tr>
      <tr>
        <td align="right"><label for="Name">姓&nbsp;&nbsp;&nbsp;名：</label></td>
        <td><input type="text" id="Name" name="Name" placeholder="Name" value="<?=$Name ?>"></td>
      </tr>
      <tr>
        <td align="right"><label for="IDcard"></label>身份证：</td>
        <td><input type="text" id="IDcard" name="IDcard" placeholder="ID card" value="<?=$IDcard ?>"></td>
      </tr>
      <tr>
      	<<td align="right"><label>性&nbsp;&nbsp;&nbsp;别：</label></td>
        <td>
          <input type="radio" <?php if ($Gender == 1): ?> checked = "checked" <?php endif ?> id="male" name="Gender" value="1"><label for="male">男</label>
          <input type="radio" <?php if ($Gender == 0): ?> checked = "checked" <?php endif ?> id="female" name="Gender" value="0" ><label for="female">女</label>
      	</td>
      </tr>
      <tr>
        <td align="right"><label for="Birth">出生年月：</label></td>
        <td><input type="date" id="Birth" name="Birth" value="<?=$Birth ?>"></td>
      </tr>
      <tr>
        <td align="right"><label for="Grade">年&nbsp;&nbsp;&nbsp;级：</label></td>
        <td>
          <select id="Grade" name="Grade">
            <?php foreach ($GradeS as $item): ?>
              <option <?php if ($item['value'] == $Grade): ?> selected="selected" <?php endif; ?> value="<?=$item['value'] ?>"><?=$item['text'] ?></option>
            <?php endforeach; ?>
          </select>
        </td>
      </tr>
      <tr>
        <td align="right"><label for="University">大&nbsp;&nbsp;&nbsp;学：</label></td>
        <td><input type="text" id="University" name="University" placeholder="University" value="<?=$University ?>"></td>
      </tr>
      <tr>
        <td align="right"><label for="School">学&nbsp;&nbsp;&nbsp;院：</label></td>
        <td><input type="text" id="School" name="School" placeholder="School" value="<?=$School ?>"></td>
      </tr>
      <tr>
        <td align="right"><label for="Major">专&nbsp;&nbsp;&nbsp;业：</label></td>
        <td><input type="text" id="Major" name="Major" placeholder="Major" value="<?=$Major ?>"></td>
      </tr>
      <tr>
        <td align="right"><label for="GPA">绩&nbsp;&nbsp;&nbsp;点：</label></td>
        <td><input type="number" step="0.01" id="GPA" name="GPA" placeholder="GPA" value="<?=$GPA ?>"></td>
      </tr>
      <tr>
        <td align="right"><label for="describ">自我介绍：</label></td>
        <td><textarea id="describ" name="describ" cols="50" rows="5"><?=$description ?></textarea></td>
      </tr>
      <tr >
      	<td align="center" colspan="2"><a href="message.php" target="_blank"><input type="submit" name="z"></a></td>
      </tr>
    </table>
    <?php if ($op == 2): ?>
    <input type="hidden" name="id" value="<?=$id ?>">
    <?php endif; ?>
  </form>
</body>
</html>